使用JavaScript更改CSS偽元素


Posted by hoyi-23 on 2021-06-17

這裡提供一個很簡單的作法:

HTML

<div class="box" some-attribute-name=""></div>

CSS

.box::before{
    content= attr(some-attribute-name);
}

JavaScript

var box = document.querySelector('.box');
box.setAttribute('some-attribute','要新增的屬性值');

#偽元素 #javascript







Related Posts

[C#] 同網站下,不同應用程式在ASP.NET MVC 使用 Owin 驗證的登入登出問題

[C#] 同網站下,不同應用程式在ASP.NET MVC 使用 Owin 驗證的登入登出問題

[TensorFlow Certification Day4] TensorFlow的人工智能, 機器學習和深度學習簡介 Week4

[TensorFlow Certification Day4] TensorFlow的人工智能, 機器學習和深度學習簡介 Week4

MTR04_0802

MTR04_0802


Comments